package L1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * 阅览室
 * %.0f是四舍五入输出整数部分
 */
public class _043 {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.valueOf(reader.readLine());
        for (int i=0;i<N;i++){
            int[][] book = new int[1001][4];
            int hh;
            int mm;
            int id;
            int count=0;
            int time;
            String flag;
            String[] s;
            int sum=0;
            while (true){
                s = reader.readLine().split(" ");
                id = Integer.valueOf(s[0]);
                flag = s[1];
                String[] split = s[2].split(":");
                hh = Integer.valueOf(split[0]);
                mm = Integer.valueOf(split[1]);
                time = hh*60+mm;
                if (id==0){
                    break;
                }
                if (flag.equals("S")){
                    book[id][0]=1;
                    book[id][1]=time;
                }else {
                    book[id][2]=1;
                    book[id][3]=time;
                    if (book[id][0]==1&&book[id][2]==1){
                        count++;
                        sum+=book[id][3]-book[id][1];
                        book[id][0]=0;
                    }
                }
            }
            if (count!=0)
                System.out.println(count+" "+String.format("%.0f",1.0*sum/count));
            else System.out.println("0"+" "+"0");
        }
    }
}
